
package com.huaweicloud.saaslanding.install.properties;

import static com.huaweicloud.saaslanding.install.constant.ModelConstant.SSL_PREFIX;

import com.huaweicloud.saaslanding.basic.utils.CheckNullUtil;

import jakarta.validation.constraints.NotNull;
import lombok.Data;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

/**
 * 功能描述
 *
 * @since 2022-08-25
 */
@Data
@Component
@Validated
@ConfigurationProperties(prefix = SSL_PREFIX)
public class Ssl {
    /**
     * 是否开启SSL认证
     */
    @NotNull
    private boolean enabled;

    /**
     * 秘钥库Base64位编码
     */
    private String keyStore;

    /**
     * 秘钥库位置
     */
    private String keyStorePath;

    /**
     * 秘钥库口令
     */
    private String keyStorePwd;

    /**
     * 信任库Base64位编码
     */
    private String trustStore;

    /**
     * 信任库位置
     */
    private String trustStorePath;

    /**
     * 信任库口令
     */
    private String trustStorePwd;

    public String getKeyStore() {
        if (enabled && CheckNullUtil.isNotNull(keyStore)) {
            return keyStore;
        } else {
            throw new IllegalArgumentException("未启用ssl或未配置秘钥库Base64位编码(ssl.keyStore)");
        }
    }

    public String getKeyStorePath() {
        if (enabled && CheckNullUtil.isNotNull(keyStorePath)) {
            return keyStorePath;
        } else {
            throw new IllegalArgumentException("未启用ssl或未配置秘钥库位置(ssl.keyStorePath)");
        }
    }

    public String getKeyStorePwd() {
        if (enabled && CheckNullUtil.isNotNull(keyStorePwd)) {
            return keyStorePwd;
        } else {
            throw new IllegalArgumentException("未启用ssl或未配置秘钥库口令(ssl.keyStorePwd)");
        }
    }

    public String getTrustStore() {
        if (enabled && CheckNullUtil.isNotNull(trustStore)) {
            return trustStore;
        } else {
            throw new IllegalArgumentException("未启用ssl或未配置信任库Base64位编码(ssl.trustStore)");
        }
    }

    public String getTrustStorePath() {
        if (enabled && CheckNullUtil.isNotNull(trustStorePath)) {
            return trustStorePath;
        } else {
            throw new IllegalArgumentException("未启用ssl或未配置信任库位置(ssl.trustStorePath)");
        }
    }

    public String getTrustStorePwd() {
        if (enabled && CheckNullUtil.isNotNull(trustStorePwd)) {
            return trustStorePwd;
        } else {
            throw new IllegalArgumentException("未启用ssl或未配置秘信任库口令(ssl.trustStorePwd)");
        }
    }
}
